package com.nineclock.system.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.system.SysCompanyUserControllerApi;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/companyUser")
public class SysCompanyUserController implements SysCompanyUserControllerApi {

    @Autowired
    SysCompanyUserService companyUserService;

    @Override
    @GetMapping("/query")
    public Result<List<SysCompanyUserDTO>> queryCompanyUser(Long companyId, Long userId) {
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryCompanyUser(companyId, userId);
        return Result.success(companyUserDTOList);
    }

    @Override
    @GetMapping("/queryone")
    public Result<SysCompanyUserDTO> findCompanyUserByMobile(String mobile) {
        SysCompanyUserDTO companyUserDTO = companyUserService.findCompanyUserByMobile(mobile);
        return Result.success(companyUserDTO);
    }

    @GetMapping("/queryAll")
    public Result<List<SysCompanyUserDTO>> findAllCompanyUser(){
        List<SysCompanyUserDTO> companyUserDTOList = companyUserService.queryAll();
        return Result.success(companyUserDTOList);
    }


    //根据企业ID查询企业的主管理员信息
    @GetMapping("/queryAdminByCompanyId")
    public Result<SysCompanyUserDTO> queryAdminByCompanyId(Long companyId){
        SysCompanyUserDTO companyUserDTO =  companyUserService.queryAdminByCompanyId(companyId);
        return Result.success(companyUserDTO);
    }

    /**
     * 根据企业用户id查询企业表该用户所有信息
     * @param companyUserId
     * @return
     */
    @GetMapping("/listSignAllUser")
    public Result<SysCompanyUserDTO> findCompanyUserId(@RequestParam("companyUserId") Long companyUserId){
        SysCompanyUserDTO sysCompanyUser = companyUserService.findCompanyUserId(companyUserId);
        return Result.success(sysCompanyUser);
    }

    @GetMapping("/sign")
    public Result<PageResult<SysCompanyUserDTO>> queryPageResult (@RequestParam("page") String page, @RequestParam("pageSize") String pageSize){
        PageResult<SysCompanyUserDTO> companyUserDTOPageResult = companyUserService.queryPageResult(page, pageSize);
        return Result.success(companyUserDTOPageResult);
    }

}
